﻿using System;

namespace _1572_matrix_diagonal_sum
{
    class Program
    {
        static void Main (string[] args)
        {
            int[][] mat = new int[3][];
            mat[0] = new int[] { 1, 2, 3 };
            mat[1] = new int[] { 4, 5, 6 };
            mat[2] = new int[] { 7, 8, 9 };

            Console.WriteLine (DiagonalSum(mat));
        }

        public static int DiagonalSum (int[][] mat)
        {
            int sum = 0;
            for (int i = 0;i < mat.GetLength(0);i++)
            {
                sum += mat[i][i];
                sum += (mat.GetLength (0) - i - 1) == i?0:mat[i][mat.GetLength (0) - i - 1];
            }
            return sum;
        }
    }
}
